package com.simon.hse.activity.safe.workpermit;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

/**
 * 作业许可证
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity__work_permit_details)
public class WorkPermitDetailsActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @ViewInject(R.id.tv_apply_work_permit_xgbg)
    TextView mTv_apply_work_permit_xgbg;

    @ViewInject(R.id.ll_danger_stop_bottom)
    LinearLayout mLl_danger_stop_bottom;

    @ViewInject(R.id.iv_common_right)
    TextView ivCommonRight;
    //            申请人
    @ViewInject(R.id.ll_applicant)
    LinearLayout llApplicant;
    //            批准人
    @ViewInject(R.id.ll_approver)
    LinearLayout llApprover;
    @ViewInject(R.id.tv_approver)
    TextView tvApprover;
    //            作业负责人
    @ViewInject(R.id.ll_responsible_person)
    LinearLayout llResponsiblePerson;
    @ViewInject(R.id.responsible_person)
    TextView responsiblePerson;
    //            属地主管
    @ViewInject(R.id.ll_supervisor)
    LinearLayout llSupervisor;
    @ViewInject(R.id.tv_supervisor)
    TextView tvSupervisor;
    @ViewInject(R.id.tv_train_record_cancel)
    TextView tvTrainRecordCancel;
    @ViewInject(R.id.tv_train_record_confirm)
    TextView tvTrainRecordConfirm;


    private boolean isShowBottom = false;

    String from;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        from = bundle.getString("from");
        switch (from) {
            //有效
            case "effective":
                ivCommonRight.setVisibility(View.VISIBLE);
                tvTrainRecordCancel.setVisibility(View.VISIBLE);
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证");
                break;
            //关闭待确认
            case "closeConfirm":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                llResponsiblePerson.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证");
                tvTrainRecordConfirm.setText("确认关闭");
                break;
            //关闭
            case "close":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                llResponsiblePerson.setVisibility(View.VISIBLE);
                llSupervisor.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证");
                tvTrainRecordConfirm.setText("返回");
                break;
            //待确认
            case "toBeConfirmed":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                tvApprover.setText("审批人");
                mTv_common_title.setText("作业许可证申请");
                tvTrainRecordConfirm.setText("提交");
                break;
            //待审批
            case "pendingApproval":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                tvApprover.setText("审批人");
                mTv_common_title.setText("作业许可证申请");
                tvTrainRecordConfirm.setText("返回");
                break;
            //超期
            case "overdue":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证");
                tvTrainRecordConfirm.setText("关闭");
                break;
            //取消
            case "cancel":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                llResponsiblePerson.setVisibility(View.VISIBLE);
                llSupervisor.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证");
                responsiblePerson.setText("取消提出人");
                tvSupervisor.setText("取消审批人");
                tvTrainRecordConfirm.setText("返回");
                break;
            //申请取消
            case "applyCancel":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                tvTrainRecordCancel.setVisibility(View.VISIBLE);
                tvTrainRecordConfirm.setText("申请取消");
                mTv_common_title.setText("作业许可证取消");
                break;
            //取消审批
            case "cancelApply":
                llApplicant.setVisibility(View.VISIBLE);
                llApprover.setVisibility(View.VISIBLE);
                llResponsiblePerson.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证取消审批");
                responsiblePerson.setText("取消提出人");
                tvTrainRecordCancel.setVisibility(View.VISIBLE);
                tvTrainRecordConfirm.setText("同意");
                break;
            default:
                ivCommonRight.setVisibility(View.VISIBLE);
                llApplicant.setVisibility(View.VISIBLE);
                ivCommonRight.setVisibility(View.VISIBLE);
                mTv_common_title.setText("作业许可证");
                break;
        }
    }

    @Event(value = {R.id.iv_common_left, R.id.iv_add_specila_work_permit, R.id.iv_common_right, R.id.tv_train_record_cancel, R.id.tv_train_record_confirm})
    private void finish(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.iv_add_specila_work_permit:
                Intent intent = new Intent(WorkPermitDetailsActivity.this, AddSpecialWorkPermitActivity.class);
                Bundle bundle = new Bundle();
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.iv_common_right:
                Intent intentRight = new Intent(WorkPermitDetailsActivity.this, WorkPermitApplyActivity.class);
                startActivity(intentRight);
                finish();
                break;
            case R.id.tv_train_record_cancel:
                finish();
                break;
            case R.id.tv_train_record_confirm:
                Intent intentConfirm = new Intent();
                switch (from) {
                    //有效
                    case "effective":
                        intentConfirm.setClass(WorkPermitDetailsActivity.this, CloseWorkPermitActivity.class);
                        startActivity(intentConfirm.putExtra("from", "effective"));
                        finish();
                        break;
                    //关闭待确认
                    case "closeConfirm":
                        intentConfirm.setClass(WorkPermitDetailsActivity.this, CloseWorkPermitActivity.class);
                        startActivity(intentConfirm.putExtra("from", "closeConfirm"));
                        finish();
                        break;
                    //关闭
                    case "close":
                        finish();
                        break;
                    //待确认
                    case "toBeConfirmed":
                        finish();
                        break;
                    //待确认
                    case "pendingApproval":
                        finish();
                        break;
                    //超期
                    case "overdue":
                        intentConfirm.setClass(WorkPermitDetailsActivity.this, CloseWorkPermitActivity.class);
                        startActivity(intentConfirm.putExtra("from", "effective"));
                        finish();
                        break;
                    //取消
                    case "cancel":
                        finish();
                        break;
                    //申请取消
                    case "applyCancel":
                        intentConfirm.setClass(WorkPermitDetailsActivity.this, WorkPermitCancelActivity.class);
                        startActivity(intentConfirm);
                        finish();
                        break;
                    //取消审批
                    case "cancelApply":
                        intentConfirm.setClass(WorkPermitDetailsActivity.this, WorkPermitCancelApprovalActivity.class);
                        startActivity(intentConfirm);
                        finish();
                        break;
                    default:
                        intentConfirm.setClass(WorkPermitDetailsActivity.this, CloseWorkPermitActivity.class);
                        startActivity(intentConfirm);
                        finish();
                        break;
                }
                break;
        }
    }
}
